package com.controller.advice;

import com.exception.SeckillException;
import com.vo.ResultVO;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice(basePackages = "com.controller")
public class ExceptionAdvice {

    @ExceptionHandler(SeckillException.class)
    public ResultVO handleSeckillException(SeckillException e) {
        System.out.println(e.getMessage());
        ResultVO vo = new ResultVO();
        vo.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        vo.setMessage(e.getMessage());
        return vo;
    }

    @ExceptionHandler(RuntimeException.class)
    public ResultVO handleRuntimeException(RuntimeException e) {
        ResultVO vo = new ResultVO();
        vo.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        vo.setMessage("服务器内部异常，请稍后尝试");
        return vo;
    }
}
